package fr.esiag.isidis.pdsTeam.beans;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import fr.esiag.isidis.pdsTeam.views.TrainView;

public class Ligne  implements Iterable<Station>{
	int id;
	Map<Integer,Station> stations;
	
	public Ligne(int id) {
		super();
		this.id = id;
		stations=new HashMap<Integer, Station>();
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
		
	}
	public int getNbStation(){
		return stations.size();
	}
	
	

    public void add(Station in)
    {
       stations.put(in.getId(),in);
    }
	
	public Station getStation(int station){
		Iterator it = stations.entrySet().iterator();
		int i=0;
	    while (it.hasNext()) {
	        Map.Entry pairs = (Map.Entry)it.next();
	        if(i==station)
	        {
	        	Station st=((Station)pairs.getValue());
	        	return st;
	        }
			
	        i++;	
	    }
		return null;
	}
	public Iterator<Station> iterator() {
		return new Iterator<Station>() {
			Iterator<Station> iterator=stations.values().iterator();
			public boolean hasNext() {
				return iterator.hasNext();
			}
			public Station next() {
				return iterator.next();
			}
			public void remove() {
				iterator.remove();
			}
		};
	}
   
}